package com.yehuishou.service.impl;


import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yehuishou.dao.SaleOrderDao;
import com.yehuishou.pojo.QueryVO;
import com.yehuishou.pojo.Brand;
import com.yehuishou.pojo.Classify;
import com.yehuishou.pojo.ImageFile;
import com.yehuishou.pojo.Models;
import com.yehuishou.pojo.Oditem;
import com.yehuishou.service.SaleOrderService;

/**
 * 用户订单业务实现层
 * @author VULCAN
 *
 */
@Service
public class SaleOrderServiceImpl implements SaleOrderService{

	@Autowired
	private SaleOrderDao saleOrderDao;

	@Override
	public int deleteUser(String oid) {

		return saleOrderDao.deleteUser(oid);	
	}
	
	@Override
	public Integer deleteItemOrder(String oid) {
		
		return saleOrderDao.deleteItemOrder(oid);
	}

	@Override
	public PageInfo<QueryVO> findUserOrder(Integer pageNum,Integer pageSize,QueryVO vo) {
		PageHelper.startPage(pageNum, pageSize);
		List<QueryVO> list =saleOrderDao.findUserOrder(vo);			
		PageInfo<QueryVO> mv =new PageInfo<QueryVO>(list);
		
		return mv;
	}

	
	//通过订单编号 查询订单下面的所有商品详情
	@Override
	public List<Oditem> finditems(String oid) {
		//查询商品详情
		List<Oditem> qu=saleOrderDao.finditems(oid);
		for (int i = 0; i <qu.size(); i++) {
			//通过循环遍历 获取每个商品详情的ID
			String img=qu.get(i).getImage();
			//查询订单详情里面是否带有图片
			if(img!=null && !img.equals("")) {
			//将详情里的图片 通过 ;号 进行分割 存到 字符串中
			String[] imgs=img.substring(1, img.length()).split(";");
				//将获得到的图片 信息 转化为 Integer 类型  
				Integer imgid=Integer.parseInt(imgs[0]);
				//查询图片地址 使用图片类接收
				ImageFile imagefile=saleOrderDao.selimg(imgid);
				//将图片地址放入到集合中
				qu.get(i).setImage(imagefile.getFilePath());
			}
		}
		return qu;
	}

	@Override
	public Integer UpdateDetails(Oditem oditem) {
		
		return saleOrderDao.UpdateDetails(oditem);
		
	}

	@Override
	public Integer detailsDelete(Integer i_id) {
		
		return saleOrderDao.detailsDelete(i_id);
		
	}

	@Override
	public Oditem FindDetailsById(Oditem oditem) {
		
			Oditem od = saleOrderDao.FindDetailsById(oditem);
			return od;

	}

	@Override
	public List<Classify> selclassify() {
		List<Classify> list = saleOrderDao.selclassify();
		return list;
	}
	
	@Override
	public List<Brand> selbrand() {
		List<Brand> brand = saleOrderDao.selbrand();
		return brand;
	}

	@Override
	public List<Models> selmodel() {
		List<Models> model = saleOrderDao.selmodel();
		return model;
	}

	@Override
	public Integer UpdateConfiguration(Oditem oditem) {
	
		return saleOrderDao.UpdateConfiguration(oditem);
	}

	@Override
	public void deleteUsers(String[] oids) {
		saleOrderDao.deleteUsers(oids);
	}

	@Override
	public void deleteItemOrders(String[] oids) {
		saleOrderDao.deleteItemOrders(oids);
	}

}
